package cloud.xlh.digital_power_pay.controller;

import cloud.xlh.digital_power_pay.client.order.dto.OrderDTO;
import cloud.xlh.digital_power_pay.client.order.service.OrderClientService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * Created with IntelliJ IDEA.
 *
 * @ project name : xlh_osms
 * @ Author: XuLeHuang
 * @ Date: 2023/8/12 18:04
 * @ Description:
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Resource
    private OrderClientService orderClientService;

    @RequestMapping("/genOrder")
    public String genOrder(@RequestBody OrderDTO orderDTO) {
        return orderClientService.genOrder(orderDTO);
    }

    @PostMapping("/order/payOrder")
    public String payOrder(JSONObject req) {
        try {
            //模拟超时
            TimeUnit.HOURS.sleep(1l);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        throw new RuntimeException("支付系统超时");
    }
}
